package com.phkj.qdh.net

import com.phkj.qdh.BuildConfig
import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import java.util.concurrent.TimeUnit

/**
 * @ProjectName:    KotlinCoroutine
 * @Package:        com.blue.kotlincoroutine.net
 * @ClassName:      OkHttpManager
 * @Description:    OkHttp客户端
 * @Author:         BLUE
 * @CreateDate:     6/1/21 4:57 PM
 * @UpdateUser:     更新者
 * @UpdateDate:     6/1/21 4:57 PM
 * @UpdateRemark:   更新说明
 * @Version:        1.0
 */
object OkHttpManager {
    val mClient by lazy(LazyThreadSafetyMode.SYNCHRONIZED){
        buildClient()
    }

    private fun buildClient():OkHttpClient{
        val logging = HttpLoggingInterceptor()
        logging.level = if (BuildConfig.DEBUG) HttpLoggingInterceptor.Level.BODY else HttpLoggingInterceptor.Level.NONE
        return OkHttpClient.Builder().apply {
            addInterceptor(CommInterceptor())
            addInterceptor(TokenInterceptor())
//            addInterceptor(logging)
            callTimeout(20, TimeUnit.SECONDS)
            connectTimeout(20, TimeUnit.SECONDS)
            readTimeout(20, TimeUnit.SECONDS)
            followRedirects(true)   //允许重定向
        }.build()
    }
}